package com.tcd.explore.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tcd.explore.pojo.VerifyLossInfo;
import com.tcd.explore.service.VerifyLossInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.management.Query;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 核损信息表 前端控制器
 * </p>
 *
 * @author Jarle
 * @since 2021-05-25
 */
@RestController
@CrossOrigin
@RequestMapping("/generator")
public class VerifyLossInfoController {
    @Autowired
    VerifyLossInfoService verify;

    @RequestMapping("/VerifyLossadd")
    public boolean VerifyLossadd(double verifyLossCost, String claimid, String verifyLossOpinion, String humanverinfototal, String carverinfototal, String objverinfototal) {
        Long id = IdWorker.getId();
        String num = 495 + "" + id.intValue();
        if (num.indexOf('-') != -1) {
            num = num.substring(0, num.lastIndexOf("-")) + num.substring(num.lastIndexOf("-") + 1, num.length() - 1);
        }
        return verify.verifysave(new VerifyLossInfo(Long.valueOf(num), Long.valueOf(claimid), BigDecimal.valueOf(verifyLossCost), verifyLossOpinion, BigDecimal.valueOf(Double.valueOf(carverinfototal)), BigDecimal.valueOf(Double.valueOf(humanverinfototal)), BigDecimal.valueOf(Double.valueOf(objverinfototal))));
    }

    @RequestMapping("/VerifyLossload")
    public Map<String, Object> vlist(int page, int pagesize) {
        Map<String, Object> map = new HashMap<>();
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("verifystatus", 1);
        List<VerifyLossInfo> list = verify.list(wrapper);
        map.put("count", list.size());
        List<VerifyLossInfo> listsplice = verify.verifylistsplice(page, pagesize);
        map.put("list", listsplice);
        return map;
    }

    @RequestMapping("/VerifyLossdel")
    public boolean VerifyLoassdel(String verifyid) {
        return verify.removeById(verifyid);
    }

    @RequestMapping("/VerifyLosslist")
    public List<VerifyLossInfo> vlist(String uid) {
        return verify.verifylisttow(uid);
    }

    @RequestMapping("/updateVerifyLossstatus")
    public boolean updateVerifystatus(String[] vid, String uid) {
        boolean flag = false;
        for (String i : vid) {
            flag = verify.updateverify(i, uid);
        }
        return flag;
    }
}

